package aygx.spring.boot.principle.config;

import aygx.spring.boot.principle.service.impl.ScheduleService3Impl;
import aygx.spring.boot.principle.service.impl.ScheduleServiceImpl;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author 暗影孤星
 * @date 2022/7/25 23:02
 * @description 通过BeanDefinition的注册器注册实名bean，实现对容器中bean的裁定，例如对现有bean的覆盖进而达成不修改源代码的情况下更换实现的效果
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        registry.registerBeanDefinition("scheduleService", BeanDefinitionBuilder.rootBeanDefinition(ScheduleService3Impl.class).getBeanDefinition());
    }
}